package com.ny.dao.impl;

import com.ny.dao.OrderDao;
import com.ny.entity.Order;
import com.ny.until.DbUntil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class OrderDaoImpl implements OrderDao {
    private DbUntil dbUntil = new DbUntil();
    @Override
    public int insertOrder(Order order) throws SQLException, ClassNotFoundException {
        Connection connection = dbUntil.getCon();
        String sql = "INSERT INTO orders(student_id, product_id, number, total_price) VALUES (?, ?, ?, ?)";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setInt(1, order.getStudentId());
        preparedStatement.setInt(2, order.getProductId());
        preparedStatement.setInt(3, order.getNumber());
        preparedStatement.setDouble(4, order.getPrice());
        return preparedStatement.executeUpdate();
    }

}
